/*
 * User: user
 * Date: 10/12/2007
 * Time: 15:32:07
 */
package org.conann.metadata.scanning;

import static com.google.common.base.Preconditions.checkNotNull;
import org.conann.metadata.records.MethodRecord;
import org.conann.metadata.records.TypeRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class ClassScanner extends ElementScanner<TypeRecord<?>, Class<?>> {

    private static final Logger log = LoggerFactory.getLogger(ClassScanner.class);
    private final MethodScanner methodScanner = new MethodScanner();

    @Override
    public TypeRecord<?> scan(Class<?> type) {
        checkNotNull(type);
        TypeRecord<?> record = new TypeRecord(type);

        scanMethods(record);

        if (log.isDebugEnabled()) {
            log.debug("Record created for " + type);
        }
        return record;
    }

    private void scanConstructors(TypeRecord<?> record) {
        Constructor<?>[] contructors = record.getType().getDeclaredConstructors();
        for (Constructor<?> constructor : contructors) {

        }
    }

    private void scanMethods(TypeRecord<?> record) {
        for (Method method : record.getType().getDeclaredMethods()) {
            MethodRecord methodRecord = methodScanner.scan(method);
            record.addRecord(methodRecord);
        }
    }
}